//用户名的提示框p标签，点击时提醒
var user_preg=/^[\u4e00-\u9fa5_a-zA-Z0-9_]{2,20}$/;
var pass_preg=/^[a-zA-Z0-9_]{6,20}$/;
var mobile_preg=/^1[3|4|5|8][0-9]{9}$/;
var email_preg=/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
$('#username').focus(function(){
           $("#user-p").css("visibility","visible");
})
$('#username').blur(function(){
           $("#user-p").css("visibility","hidden");
           user_val=$(this).val();         
           if(!user_preg.test(user_val)){
               $(this).parent().css({"border-color":"red"});
               $(this).next('img').css({"display":"none"});
               $("#user-p").css({"visibility":"visible","color":"red"}).html("用户名格式不对");
           }else{
               $(this).parent().css({"border-color":"#e3e4e9"});
               $(this).next('img').css({"display":"block"});
               $("#user-p").css("visibility","hidden");
           }
})
//密码的提示框p标签，点击时提醒
$('#password').focus(function(){
           $("#pass-p").css("visibility","visible");

})
$('#password').blur(function(){
           $("#pass-p").css("visibility","hidden");        
           pass_val=$(this).val();
           if(!pass_preg.test(pass_val)){
               $(this).parent().css({"border-color":"red"});
               $(this).next('img').css({"display":"none"});
               $("#pass-p").css({"visibility":"visible","color":"red"}).html("密码格式不对");
           }else{
               $(this).parent().css({"border-color":"#e3e4e9"});
               $(this).next('img').css({"display":"block"});
               $("#pass-p").css("visibility","hidden");
           }
})
//重复密码的提示框p标签，点击时提醒
$('#repass').focus(function(){
           $("#repass-p").css("visibility","visible");
})
$('#repass').blur(function(){           
           $("#repass-p").css("visibility","hidden");
           repass_val=$(this).val();
           if(repass_val!=pass_val){
               $(this).parent().css({"border-color":"red"});
               $(this).next('img').css({"display":"none"});
               $("#repass-p").css({"visibility":"visible","color":"red"}).html("两次密码不符合"); 
           }else{
               $(this).parent().css({"border-color":"#e3e4e9"});
               $(this).next('img').css({"display":"block"});
               $("#pass-p").css("visibility","hidden");
           }
})
//手机的提示框p标签，点击时提醒
$('#mobile').focus(function(){
           $("#mobile-p").css("visibility","visible");
           
})
$('#mobile').blur(function(){
           $("#mobile-p").css("visibility","hidden");
           mobile_val=$(this).val();  
           if(!mobile_preg.test(mobile_val)){
               $(this).parent().css({"border-color":"red"});
               $(this).next('img').css({"display":"none"});
               $("#mobile-p").css({"visibility":"visible","color":"red"}).html("手机号格式不对");
           }else{
               $(this).parent().css({"border-color":"#e3e4e9"});
               $(this).next('img').css({"display":"block"});
               $("#mobile-p").css("visibility","hidden");
           }
})
//email的提示框p标签，点击时提醒
$('#email').focus(function(){
           $("#email-p").css("visibility","visible");          
})
$('#email').blur(function(){
           $("#email-p").css("visibility","hidden");
            email_val=$(this).val();
           if(!email_preg.test(email_val)){
               $(this).parent().css({"border-color":"red"});
               $(this).next('img').css({"display":"none"});
               $("#email-p").css({"visibility":"visible","color":"red"}).html("邮箱格式不对");
           }else{
               $(this).parent().css({"border-color":"#e3e4e9"});
               $(this).next('img').css({"display":"block"});
               $("#email-p").css("visibility","hidden");
           }
})
//验证码的提示框p标签，点击时提醒
$('#verify').focus(function(){
           $("#verify-p").css("visibility","visible");
})
$('#verify').blur(function(){
           $("#verify-p").css("visibility","hidden");
})
 
 //汇一家商业用户注册协议，点击时提醒
document.getElementById("deal").addEventListener('click',function(){
           document.getElementById("fixed").style.display="block";
},false)
document.getElementById("btn").addEventListener('click',function(){
           document.getElementById("fixed").style.display="none";
},false)


$('.verify_img').click(function(){
     $(this).attr("src",verifyUrl);
})
// ajax接受
$('#submit').click(function(){
    user_val  =$('#username').val(); 
    pass_val  =$('#password').val();  
    repass_val=$('#repass').val();  
    mobile_val=$('#mobile').val();  
    email_val =$('#email').val();
    if(user_preg.test(user_val) && pass_preg.test(pass_val) && repass_val==pass_val &&
       mobile_preg.test(mobile_val) && email_preg.test(email_val)){        
           if($('#check').attr("checked")=="checked"){
              var xpl=new XMLHttpRequest();
              xpl.open("POST",ajaxUrl,true);
              var data=new FormData(document.getElementById('form'));
              xpl.responseType='json';
              xpl.send(data);
              xpl.onload=function(){
                   if(xpl.status==200){
                         var result=xpl.response;
                         if(result.code==1){
                              window.location.href=sussUrl;
                         }else if(result.code==0){
                              console.log(result.content);
                              $('#error').html(result.content);
                         }
                   }
              }
            }
            else{
              alert('阅读没同意');
            }
            
    }else{
          alert('不能提交');
    }
})